import { useStorage } from '@/utils';
import { ref } from 'vue';
const defaultStatus={
    sound:false,
    tabbar:[{
        page: "SWITCH",
        url:"/pages/index/index",
        image:"../../static/tabs/icon-1.png",
        image_2: "../../static/tabs/icon-1-selected.png",
        title: "首页"
    },{
        page: "SWITCH",
        url:"/pages/record/index",
        image: "../../static/tabs/icon-2.png",
        image_2: "../../static/tabs/icon-2-selected.png",
        title: "记录"
    },{
        page: "SWITCH",
        url:"/pages/user/index",
        image: "../../static/tabs/icon-3.png",
        image_2: "../../static/tabs/icon-3-selected.png",
        title: "我的"
    }]
};
export default () => {
    const storage = useStorage()
    const StatusStorageKey = 'GLOBALSTATUS'
    const GLOBALSTATUS = ref<StatusInterface>(defaultStatus);
    const set = (key:string,value:any): Promise<boolean | string> => {
        GLOBALSTATUS.value[key] = value;
        return storage.set(StatusStorageKey, GLOBALSTATUS.value);
    }
    const initStatus = (): void => {
        const data = storage.get(StatusStorageKey)
        if (data !== null) {
            GLOBALSTATUS.value = data;
        }
    }
    const resetTabbar=()=>{
        GLOBALSTATUS.value.tabbar = defaultStatus.tabbar;
    }
    const clearStatus = (): Promise<boolean> => {
        GLOBALSTATUS.value = defaultStatus;
        return storage.remove(StatusStorageKey)
    }
    return {
        GLOBALSTATUS,
        set,
        initStatus,
        clearStatus,
        resetTabbar
    };
}